﻿@inherits ButtonParameters
@namespace BlazorFluentUI
@using Microsoft.AspNetCore.Components.Web

@{
    RenderFragment RenderPrimaryButton() => __builder =>
    {
        if (Primary)
        {
            __builder.OpenComponent(0, typeof(PrimaryButton));
        }
        else
        {
            __builder.OpenComponent(0, typeof(DefaultButton));
        }
        __builder.AddAttribute(1, "Href", Href);
        __builder.AddAttribute(2, "ClassName", ClassName + " ms-Button--commandBar");
        __builder.AddAttribute(3, "Style", Style);
        __builder.AddAttribute(4, "Primary", Primary);
        __builder.AddAttribute(5, "Disabled", Disabled);
        __builder.AddAttribute(6, "AllowDisabledFocus", AllowDisabledFocus);
        __builder.AddAttribute(7, "PrimaryDisabled", PrimaryDisabled);
        __builder.AddAttribute(8, "Checked", Checked);
        __builder.AddAttribute(9, "AriaDescripton", AriaDescripton);
        __builder.AddAttribute(10, "Text", Text);
        __builder.AddAttribute(11, "SecondaryText", SecondaryText);
        __builder.AddAttribute(12, "Toggle", Toggle);
        __builder.AddAttribute(13, "Split", Split);
        __builder.AddAttribute(14, "IconName", IconName);
        __builder.AddAttribute(15, "IconSrc", IconSrc);
        __builder.AddAttribute(16, "HideChevron", HideChevron);
        __builder.AddAttribute(17, "MenuItems", MenuItems);
        __builder.AddAttribute(18, "SubordinateItemTemplate", SubordinateItemTemplate);
        __builder.AddAttribute(19, "CheckedChanged", CheckedChanged);
        __builder.AddAttribute(10, "OnClick", OnClick);
        __builder.AddAttribute(21, "OnKeyDown", OnKeyDown);
        __builder.AddAttribute(22, "Command", Command);
        __builder.AddAttribute(23, "CommandParameter", CommandParameter);
        //       __builder.AddAttribute(24, "UnknownProperties", UnknownProperties);
        //    __builder.AddAttribute(25, "ContextMenuShown", contextMenuShown);
        //    __builder.AddAttribute(26, "ContextMenuShownChanged", Microsoft.AspNetCore.Components.EventCallback.Factory.Create<System.Boolean>(this, Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => contextMenuShown = __value, contextMenuShown)));

        __builder.AddAttribute(25, "ref", Primary ? "primaryButtonReference" : "defaultButtonReference");

        if (ContentTemplate != null)
        {
            __builder.AddAttribute(26, "ContentTemplate", ContentTemplate);
        }
        if (MenuItemTemplate != null)
        {
            __builder.AddAttribute(27, "MenuItemTemplate", MenuItemTemplate);
        }
        if (ChildContent != null)
        {
            __builder.AddAttribute(28, "ChildContent", ChildContent);
        }
        __builder.AddAttribute(29, "IsRadioButton", IsRadioButton);
        __builder.AddAttribute(30, "GroupName", GroupName);
        __builder.AddAttribute(31, "SplitButtonAriaLabel", SplitButtonAriaLabel);


        __builder.AddComponentReferenceCapture(31, (__value) =>
        {
            if (Primary)
            {
                primaryButtonReference = (PrimaryButton)__value;
            }
            else
            {
                defaultButtonReference = (DefaultButton)__value;
            }
        }
        );

        __builder.CloseComponent();
    };
}
@RenderPrimaryButton()


@code{
    private DefaultButton defaultButtonReference = new DefaultButton();
    private PrimaryButton primaryButtonReference = new PrimaryButton();
    protected override void OnAfterRender(bool firstRender)
    {
        if (Primary)
            RootElementReference = primaryButtonReference.RootElementReference;
        else
            RootElementReference = defaultButtonReference.RootElementReference;
        base.OnAfterRender(firstRender);
    }
}
